{extend name="public:head"}
{block name="main"}

<!--<form class="layui-form" action="/admin/Banner/addBannerPic" method="POST">-->
<form class="layui-form" lay-filter="addSign">

    <div class="layui-form-item">
        <label class="layui-form-label " style="width: 100px">渠道名称</label>
        <div class="layui-input-inline">
            <input type="hidden" name="id" value="{$info['sign_id']|default=''}">
            <input type="text" name="channel" placeholder="请输入渠道名称" id="channel" class="layui-input" lay-verify="required" value="{$info['channel']|default=''}" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label " style="width: 100px">推广标识</label>
        <div class="layui-input-inline">
            <input type="text" name="sign" placeholder="" id="sign" class="layui-input" lay-verify="required" value="{$info['sign']|default=''}" {if $info['sign_id'] !== ''}disabled{/if}>
        </div>
        <div class="layui-input-inline">
            <a class="layui-btn layui-btn-warm" onclick="javascript:randomPassword(5, 'sign')">随机生成</a>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label " style="width: 100px">密码</label>
        <div class="layui-input-inline">
            <input type="text" name="pwd" placeholder="" id="pwd" class="layui-input" lay-verify="required" value="{$info['pwd']|default=''}">
        </div>
        <div class="layui-input-inline">
            <a class="layui-btn layui-btn-warm" onclick="javascript:randomPassword(8, 'pwd')">随机生成</a>
        </div>
    </div>

<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label " style="width: 100px">流量隐藏倍数</label>-->
<!--        <div class="layui-input-inline">-->
<!--            <input type="text" name="pop_num" placeholder="请输入1-10整数" id="pop_num" class="layui-input" >-->
<!--        </div>-->
<!--    </div>-->

<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label " style="width: 100px">注册隐藏倍数</label>-->
<!--        <div class="layui-input-inline">-->
<!--            <input type="text" name="reg_num" placeholder="请输入1-10整数" id="reg_num" class="layui-input" >-->
<!--        </div>-->
<!--    </div>-->

<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">域名</label>-->
<!--        <div class="layui-input-block">-->
<!--            <input type="checkbox" name="like[write]" title="单期">-->
<!--            <input type="checkbox" name="like[read]" title="分期">-->
<!--        </div>-->
<!--    </div>-->

    <div class="layui-form-item">
        <label class="layui-form-label"  style="width: 100px">状态</label>
        <div class="layui-input-block">
            <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|禁用" lay-filter="switchTest" {if $info.status == 1}checked {/if}>
            <div class="layui-unselect layui-form-switch" lay-skin="_switch">
                <em>OFF</em><i></i>
            </div>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button lay-submit class="layui-btn"  lay-filter="buttonSign">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>

<script type="text/javascript">


    layui.use(['form','layedit'], function(){
        var form = layui.form
        var layer = layui.layer;
        // var $= layui.jquery;
        var token = layui.data('cache').token;

        form.on('submit(buttonSign)', function(data){
            console.log(data)
            $.ajax({
                url:"/login/Sign/signApi",
                type:"post",
                headers:{"token":token},
                data:{"data":data.field},
                dataType:"json",
                success:function (res) {
                    layer.msg(res.msg)
                    setTimeout(function (){
                        window.location.href = "/login/Sign/allSign"
                    }, 3000)

                },
                error:function (error) {
                    console.log(error.msg)
                }
            })
            return false;
        });
    });

    // 随机生成密码
    function randomPassword(size, idNum)
    {
        var seed = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z',
            'a','b','c','d','e','f','g','h','i','j','k','m','n','p','Q','r','s','t','u','v','w','x','y','z',
            '2','3','4','5','6','7','8','9'
        );//数组
        seedlength = seed.length;//数组长度
        var createPassword = '';
        for (i=0;i<size;i++) {
            j = Math.floor(Math.random()*seedlength);
            createPassword += seed[j];
        }
        $("#"+idNum).val(createPassword);
    }

</script>

{/block}